<!--生存认定-->
<template>
    <div ref="body">
        <Form :label-width="120" inline>
            <Form-item label="救助类别">
                <dictSelect :sel_val='queryParam.ssca0002' dictCode="assistancetype" :bindData.sync="queryParam.ssca0002" style="width: 200px" showKeys="100,200"/>
            </Form-item>
            <Form-item label="属地区划:">
                <area-linkage :areaCode.sync="queryParam.azaa0001"></area-linkage>
            </Form-item>
            <Form-item label="认定结果:">
                <Select v-model="queryParam.yjae0006" placeholder="请选择办理状态" style="width:200px" clearable>
                    <Option value="0">未认定</Option>
                    <Option value="1">通过</Option>
                    <Option value="2">不通过</Option>
                </Select>
            </Form-item>
            <Form-item label="认定年月:"  >
                <DatePicker type="month" v-model="queryParam.yjae0005" placeholder="请选择认定年月"
                            class="time"  :editable="false"></DatePicker>
            </Form-item>
            <Form-item label="申请人姓名:">
                <Input v-model="queryParam.azcp0003" placeholder="" style="width:200px"/>
            </Form-item>

            <Form-item label="申请人证件号码:">
                <Input v-model="queryParam.azcp0001" placeholder="" style="width:200px"/>
            </Form-item>
            <span v-if="show">
                <Form-item label="家庭编号:">
                <Input v-model="queryParam.azdf0001" placeholder="" style="width:200px"/>
            </Form-item>
            <Form-item label="受理编号:">
                <Input v-model="queryParam.ssca0061" placeholder="" style="width:200px"/>
            </Form-item>
            <Form-item label="低保证号:">
                <Input v-model="queryParam.ssca0014" placeholder="" style="width:200px"/>
            </Form-item>
            <Form-item label="性别:" >
                <c-dict-select v-model="queryParam.azcp0004" dictCode="sex" placeholder="请选择性别"/>
            </Form-item>
            <Form-item label="民族:" >
                <c-dict-select v-model="queryParam.azcp0007" dictCode="nation"
                               placeholder="请选择民族"/>
            </Form-item>

            <Form-item label="健康状况:" >
                <c-dict-select v-model="queryParam.azcp0009" dictCode="health"
                               placeholder="请选择健康状况"/>
            </Form-item>

            <Form-item label="残疾类别:" >
                <c-dict-select v-model="queryParam.azcp0504" dictCode="disabilitytype"
                               placeholder="请选择残疾类别"/>
            </Form-item>

            <Form-item label="残疾等级:" >
                <c-dict-select v-model="queryParam.azcp0505" dictCode="disabilityclass"
                               placeholder="请选择残疾等级"/>
            </Form-item>
                 <Form-item label="致贫原因:" >
                    <c-dict-select v-model="queryParam.ssca0013" dictCode="poorreason"
                                   placeholder="请选择致贫原因"/>
                </Form-item>
            </span>
            <div style="display: inline-block;cursor:pointer" @click="showHidden">
                <template v-if="show">
                    <Form-item label="收起条件" style="cursor:pointer">
                        <div class="ivu-form-item">
                        <span class="ivu-input-suffix">
                          <Icon type="ios-arrow-up"/>
                        </span>
                        </div>
                    </Form-item>
                </template>
                <template v-else>
                    <Form-item label="展开条件" style="cursor:pointer">
                        <div class="ivu-form-item">
                        <span class="ivu-input-suffix">
                            <Icon type="ios-arrow-down"/>
                        </span>
                        </div>
                    </Form-item>
                </template>
            </div>
            <Row style="padding: 8px">
                <span style="float: left;">
                  <Button type="primary" style="" @click="showScrd()" icon="ios-brush">手工生存认定</Button>
                  <Button type="primary" style="margin-left: 8px" @click="scrdHistory()" icon="md-remove-circle">生存认定历史</Button>
                </span>
                <span style="float: right;">
                <Button type="primary" style="" @click="searchQuery">查询</Button>
                 <Button type="primary" style="margin-left: 8px" @click="searchReset">重置</Button>
                     </span>
            </Row>
        </Form>
        <Modal v-model="modalShow" title="手动生存认定" :mask-closable="false" width="500" >
            <Form :model="formItem" :label-width="100"  >
                <FormItem label="生存认定说明:"     >
                    <font color="red">每个月只能认定一次</font>
                </FormItem>

                <FormItem label="姓名:" prop="yjae0002">
                    <Input v-model="formItem.yjae0002"   :disabled="cantEdit" placeholder="" ></Input>
                </FormItem>
                <FormItem label="身份证号:" prop="yjae0001">
                    <Input  v-model="formItem.yjae0001"  :disabled="cantEdit"  placeholder="" ></Input>
                </FormItem>

                <FormItem label="认定时间:" prop="yjae0005">
                    <Input  v-model="formItem.yjae0005"  :disabled="cantEdit"  placeholder="" ></Input>
                </FormItem>
                <Form-item label="是否认定通过:" prop="yjab0006">
                    <Select v-model="formItem.yjae0006" placeholder="请选择" style="width:200px">
                        <Option value="1">通过</Option>
                        <Option value="2">不通过</Option>
                    </Select>
                </Form-item>
                <FormItem label="认定说明:" prop="yjae0010">
                    <Input  v-model="formItem.yjae0010"    type="textarea" :rows="4" placeholder="" ></Input>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="info"   @click="addScrd()">保存</Button>
                <Button type="default" @click="modalShow=false">关闭</Button>
            </div>
        </Modal>
        <div style="margin-top:10px ">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       @cell-click="selectChange"
                       :data="tableData">
                <vxe-table-column type="radio" width="60" align="center" fixed="left"/>
                <vxe-table-column field="ssca0043" title="属地区划" align="center" width="220" fixed="left"/>
                <vxe-table-column field="hzname" title="户主姓名" align="center" width="100" fixed="left"/>
                <vxe-table-column field="azcp0003" title="成员姓名" align="center" width="100" fixed="left"/>
                <vxe-table-column field="azcp0001" title="申请人身份证号码" align="center" width="180" fixed="left"/>
                <vxe-table-column field="yjae0006" title="认证结果" align="center" width="140"/>
                <vxe-table-column field="yjae0005" title="认证时间" align="center" width="140" :formatter="renderTime"/>
                <vxe-table-column field="prsnage" title="年龄" align="center" width="80"/>
                <vxe-table-column field="ssca0014" title="低保证号" align="center" width="180"/>
                <vxe-table-column field="ssca0011" title="银行帐号" align="center" width="180"/>
                <vxe-table-column field="azdf0001" title="家庭编号" align="center" width="180"/>
                <vxe-table-column field="ssca0061" title="受理编号" align="center" width="180"/>
                <vxe-table-column title="操作" align="center" width="170" fixed="right">
                    <template #default="{row}">
                        <Button type="default" @click="searchDetail(row)">查看详情</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange"></Page>
        </div>
        <Modal v-model="scrd" title="生存认定历史记录" width="1200" style="position:relative;">
            <div>
                <Table :columns="columnsscrd" :data="scrdData" :loading="Loading"></Table>
                <Page :total="dataCountNoscrd" :page-size="pageSize" show-total class="paging"
                      @on-change="handleTableChangeV"></Page>
            </div>
            <br>
            <br>
            <div slot="footer">
                <Button type="text" size="large" @click="scrd = false">取消</Button>
            </div>
        </Modal>
        <application-modal  ref="modal"/>
    </div>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {getAction, postAction} from '@/api/request'
    import DateFormat from '@/plugins/format.js'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import applicationModal from '../db_application_history/applicationModal'

    export default {
        name: "ss02019List",
        components: {applicationModal,dictSelect},
        mixins: [CommonMixin],
        data() {
            return {
                cantEdit: true,
                dataCountNoscrd:0,
                scrd:false,
                scrdData: [],
                columnsscrd: [
                    {
                        title: '行政区划',
                        align: 'center',
                        key: 'azaa0002',
                        width: 220,
                    },
                    {
                        title: '身份证号码',
                        align: 'center',
                        key: 'yjae0001',
                        width: 170,
                    },
                    {
                        title: '姓名',
                        align: 'center',
                        key: 'yjae0002',
                        width: 150,
                    },
                    {
                        title: '认定时间',
                        align: 'center',
                        key: 'yjae0005',
                        width: 120,
                        render: (h, params) => {
                            let value = params.row.yjae0005
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            }else{
                                value = DateFormat( value, 'YYYY-MM-DD')
                            }
                            return h('span', value + ' ')
                        }
                    },
                    {
                        title: '认定结果',
                        align: 'center',
                        key: 'yjae0006',
                        width: 100,
                    },
                    {
                        title: '认定类别',
                        align: 'center',
                        key: 'yjae0007',
                        width: 200,
                        render: (h, params) => {
                            let value = params.row.yjae0007
                            if ( value === '1' ) {
                                value = '自动'
                            }else{
                                value = '手动'
                            }
                            return h('span', value + ' ')
                        }
                    },
                    {
                        title: '接入流水号',
                        align: 'center',
                        key: 'pshr0007',
                        width: 200,
                    },{
                        title: '接入时间',
                        align: 'center',
                        key: 'yjae0014',
                        width: 120,
                        render: (h, params) => {
                            let value = params.row.yjae0014
                            if (typeof (value) === 'undefined' || value === null || value === '' || value === undefined) {
                                value = '--'
                            }else{
                                value = DateFormat( value, 'YYYY-MM-DD')
                            }
                            return h('span', value + ' ')
                        }
                    },
                ],
                selectRow: {},
                modalShow:false,
                formItem:{},
                key: "",
                width: 1200,
                title: '',
                visible: false,
                queryParam: {},
                conversionTypes: [],
                Loading: true,
                show: false,
                url: {
                    list: "/api/ac/subsistence/ss02019Service/findPageList",
                },
                dictList: [],
            }
        },
        created() {
            this.loadData(1);
        },
        methods: {
            handleTableChangeV(index){
                let that = this;
                var dataParam = {
                    pageNo : index,
                    azcp0001:that.selectRow.azcp0001}
                let url = "/api/ac/subsistence/ss02019Service/findList";
                postAction(url, dataParam).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.scrdData = res.data.data.results;
                        that.dataCountNoscrd = res.data.data.totalRecord;
                    }
                }).finally(() => {
                    that.Loading = false;
                });
            },
            selectChange({row}) {
                this.$refs.xTree.setRadioRow(row);
                this.selectRow = row;
            },
            showScrd(){
                if(this.selectRow) {
                     this.modalShow = true;
                     this.formItem.yjae0001 = this.selectRow.azcp0001;
                     this.formItem.yjae0002 = this.selectRow.azcp0003;
                     this.formItem.yjae0006 = '';
                     this.formItem.yjae0010 = '';
                     var nowTime = new Date();
                     var nowTimeStr = nowTime.toLocaleDateString().split('/').join('-');
                     this.formItem.yjae0005 = nowTimeStr;
                } else {
                    this.$Message.error("请选择数据！")
                }
            },
            scrdHistory(){
                if(this.selectRow.azcp0001) {
                     this.scrd = true;
                     let that = this;
                    that.Loading = true;
                     var dataParam = {
                         yjae0001:this.selectRow.azcp0001}
                    let url = "/api/ac/subsistence/ss02019Service/findList";
                    postAction(url, dataParam).then((res) => {
                        if (res.data.errcode != 0) {
                            this.$Message.error(res.data.errmsg);
                        } else {
                            that.scrdData = res.data.data.results;
                            that.dataCountNoscrd = res.data.data.totalRecord;
                        }
                    }).finally(() => {
                        that.Loading = false;
                    });
                } else {
                    this.$Message.error("请选择数据！")
                }
            },
            searchDetail(row) {
                row.processinstid = row.ywgl004;
                var width = this.$refs.body.clientWidth;
                this.$refs.modal.edit(row);
                this.$refs.modal.width = width + 40;
                this.$refs.modal.key = this.uuid();
            },
            addScrd() {
                this.$Modal.confirm({
                    title: '确定进行生存认定吗？',
                    onOk: () => {
                        if(this.formItem.yjae0006=='') {
                            this.$Message.error('请选择认定结果')
                        } else {
                            let url = '/api/ac/subsistence/ss02019Service/insert';
                            let dataParam = {
                                yjae0001:this.formItem.yjae0001,
                                yjae0005:this.formItem.yjae0005,
                                yjae0006:this.formItem.yjae0006,
                                yjae0010:this.formItem.yjae0010,
                            }
                            postAction(url, dataParam).then((res) => {
                                this.selectRow = null;
                                if(res.data.data.code!='1') {
                                    this.$Message.error(res.data.data.message)
                                } else {
                                    this.$Message.info(res.data.data.message)
                                    this.modalShow = false;
                                    this.loadData(1);
                                }
                            });
                        }
                    }
                })

            },
            showHidden() {
                this.show = !this.show;
            },
            cancel() {
                this.visible = false;
            },
            loadData(arg) {
                if (arg == 1) {
                    this.pageNo = 1;
                }
                let that = this;
                that.Loading = true;
                if (this.queryParam.yjae0005 != undefined && this.queryParam.yjae0005 != ''){
                    this.queryParam.yjae0005 = DateFormat( this.queryParam.yjae0005, 'YYYY-MM')
                }
                let param = Object.assign({}, this.queryParam);
                let url = this.url.list;
                param.pageNo = this.pageNo;
                param.pageSize = this.pageSize;
                postAction(url, param).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.tableData = res.data.data.results;
                        that.dataCount = res.data.data.totalRecord;
                    }
                }).finally(() => {
                    that.Loading = false;
                })
            },edit(record) {
                this.title = '城市低保政策咨询登记';
                var width = this.$refs.body.clientWidth;
                this.$nextTick(() => {
                    this.$refs.modal.edit(record);
                    this.$refs.modal.width = width + 100;
                    this.$refs.modal.key = this.uuid();
                });
            },
            todo(type) {
                this.title = '城市低保政策咨询登记';
                if(type=='200'){
                    this.title = '农村低保政策咨询登记';
                }
                let dataParam = {
                    ssca0002: type,
                    azcp0001: '',
                }
                var width = this.$refs.body.clientWidth;
                this.$nextTick(() => {
                    this.$refs.modal.edit(dataParam);
                    this.$refs.modal.width = width + 100;
                    this.$refs.modal.key = this.uuid();
                });
            },
            modalFormOk() {
                this.selectRow = null;
                // 新增/修改 成功时，重载列表
                this.loadData();
            },
        },

    }
</script>

<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }

    /deep/ .ivu-table-cell {
        padding-right: 0px;
        padding-left: 0px;
    }

    /deep/ .ivu-form-item {
        margin-bottom: 10px;
    }
    /deep/ .ivu-modal-footer {
        border-top: 0px;
        padding: 0px;
    }
    #statistics {
        height: 50px;
        line-height: 50px;
        width: 100%;
        color: red;
        font-size: 16px;
    }

    #statistics span {
        padding-left: 10px;
        padding-right: 10px;
    }

</style>
